<template>
  <div>
    <fieldset>
      <legend style="margin-left:-12px;" class="field-title">借款详情</legend>
      <config-form :initData="allForm" :span="8" :options="DETAIL_FORM" />
    </fieldset>
    <fieldset>
      <legend style="margin-left:-12px;" class="field-title">还款详情</legend>
      <config-form :initData="allForm" :span="8" :options="CUS_FORM" />
    </fieldset>
    <fieldset>
      <legend style="margin-left:-12px;" class="field-title">受理人信息</legend>
      <config-form :initData="allForm" :span="8" :options="ACC_FORM" />
    </fieldset>
    <div style="margin-top: 25px;text-align: right;">
      <el-button type="primary" @click="close" plain>知道了</el-button>
    </div>
  </div>
</template>

<script>
import { DETAIL_FORM, CUS_FORM, ACC_FORM } from '../js/contant.js'
import api from '../api'
import { CONSTANT_OBJ } from '@/utils/constant'
import { mapState } from 'vuex'
export default {
  props: {
    editData: Object,
    flag: String
  },
  data () {
    return {
      DETAIL_FORM,
      CUS_FORM,
      ACC_FORM,
      allForm: {}
    }
  },
  mounted () {
    this.allForm = {...this.editData}
    this.getBasicInfo()
  },
  methods: {
    // 获取基本信息
    getBasicInfo () {
      api.getBasicInfoData(this.allForm.caseId).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          this.getCustomerInfomation(data)
        }
      })
    },
    // 获取申请客户信息
    getCustomerInfomation (bData) {
      api.getCustomerInfo(this.allForm.caseId).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          data.idDate = `${data.idBeginDate}-${data.idEndDate}`
          data.newEducation = this.dicts['education'].childMap[data.education]
          data.newHouseStatus = this.dicts['house_status'].childMap[data.houseStatus]
          data.newMaritalStatus = this.dicts['marital_status'].childMap[data.maritalStatus]
          data.nowAddr = `${data.homeAddress.province}-${data.homeAddress.city}-${data.homeAddress.town}-${data.homeAddress.street}`
          let cData = Object.assign(bData, data)
          // this.allForm = {...Object.assign(this.allForm, cData)}
          this.certDetails(cData)
        }
      })
    },
    // 查询提前结清内容
    certDetails (bData) {
      api.certDetailsInfo({quotaDrawId: this.allForm.quotaDrawId}).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          let cData = Object.assign(bData, data)
          this.allForm = {...Object.assign(this.allForm, cData)}
        }
      })
    },
    close () {
      this.$emit('close', false)
    }
  },
  computed: {
    ...mapState({
      dicts: state => state.common.dicts
    })
  }
}
</script>

<style lang="less" scoped>
.carve-up {
  height: 20px;
  margin: 30px 0 10px 0;
  border-top: 1px solid #ddd;
}
</style>
